<template>
  <div class="box">
    <span class="title">数字化转型调查</span>
    <!-- 服务管理 -->
    <div class="innerPageTable-box-OneTwo value-set-list-wrap innerPageTable-out-flex">
      <!-- 搜索区域 -->
      <SelfAdaption>
        <Form
          :model="searchForm"
          ref="serviceForm"
          slot="adaption-bar"
          label-position="top"
          class="ivu-form-no-margin-bottom"
          inline
        >
          <Form-item prop="vsCode" :label="'报表名称'">
            <Input
              type="text"
              v-model.trim="searchForm.serviceName"
              :placeholder="'请输入'"
              @on-enter="searchValueSet"
            ></Input>
          </Form-item>

          <!-- 查询\重置按钮 -->
          <Form-item prop="button" class="search-solt-btn">
            <RPButton optType="search" @click="searchValueSet()" />
          </Form-item>
        </Form>
      </SelfAdaption>
      <InnerPageTable ref="valueSetTable" :config="pageTableConfig"> </InnerPageTable>
    </div>
  </div>
</template>

<script>
import { tableColumns } from './columns'
import listPage from './list.vue'
import statisticPage from './statistic.vue'
import permission from '@/mixin/permission'
import coverApi from '../../api/cover'
export default {
  name: 'questionnaire',
  mixins: [permission],
  data() {
    return {
      url2022: '',
      url2021: '',
      searchForm: {
        serviceName: ''
      },
      pageTableConfig: {
        loadDataFn: this.getServiceList,
        columns: tableColumns.bind(this)(),
        autoFirst: false //默认 就是 false, 要配置在这里
      }
    }
  },

  mounted: function() {
    this.init()
    this.searchValueSet()
    if (this.$route.query.keyNumber) {
      this.statisticsFun()
    }
  },
  methods: {
    init() {
      this._getReportUrl()
      if (!this.$route.query.modal) return
      this.checkFun({ id: 1 })
    },
    _getReportUrl() {
      coverApi.getCodeList('LESS_CODE_PAGES').then(res => {
        let rescords = res.data.records
        if (rescords.length > 0) {
          const list = []
          rescords.forEach(item => {
            if ('REPORT_2022' == item.vsiKey) {
              this.url2022 = item.vsiDescription
            } else if ('REPORT_2021' == item.vsiKey) {
              this.url2021 = item.vsiDescription
            }
          })
        }
      })
    },

    //查看
    managementFun(row) {
      if (row.type == 1) {
        new this.$sidelipPage(listPage, {
          props: {
            onlyRead: true,
            id: row.id || '',
            type: row.type,
            typeName: row.name,
            oldTypeName: row.oldName
          }
        })
      } else {
        let targetUrl = ''
        if (row.type == 2) {
          targetUrl = this.url2022
        } else if (row.type == 3) {
          targetUrl = this.url2021
        }
        if (targetUrl) {
          window.open(targetUrl, '_blank')
        }
      }
    },
    // 操作
    checkFun(row) {
      new this.$sidelipPage(listPage, {
        props: { $route: this.$route }
      })
    },
    //汇总报表
    statisticsFun() {
      new this.$sidelipPage(statisticPage, {
        props: {
          $route: this.$route,
          $router: this.$router,
          scrollKey: this.$route.query.keyNumber,
          buCode: this.$route.query.buCode,
          buName: this.$route.query.buName
        }
      })
    },
    getServiceList(tableObj) {
      let { responseProcess, param } = tableObj
      let list = []
      list.push({ oldName: '2023年华润集团数字化转型调查', name: '2023年华润集团数字化转型调查', id: 1, type: 1 })
      list.push({ oldName: '2022年华润集团数字化转型调查', name: '2022年华润集团数字化转型调查', id: 2, type: 2 })
      list.push({ oldName: '2021年华润集团数字化转型调查', name: '2021年华润集团数字化转型调查', id: 3, type: 3 })
      let records = list.filter(item => item.name.includes(this.searchForm.serviceName))
      responseProcess({
        pageNum: 1,
        pageSize: 10,
        pages: 1,
        records
      })
      //   coverApi.getPermittedTableList().then(res => {
      //     let list = []
      //     if (this.hasPermission('GROUP_VIEW_DATA')) {
      //       list.push({ oldName: '中央企业科技情况调查表', name: '中央企业科技情况调查表', id: 1, type: 1 })
      //     }
      //     let records = list.filter(item => item.name.includes(this.searchForm.serviceName))
      //     responseProcess({
      //       pageNum: 1,
      //       pageSize: 10,
      //       pages: 1,
      //       records,
      //       total: records.length
      //     })
      //   })
    },
    searchValueSet() {
      this.$refs['valueSetTable'].load(this.searchForm)
    }
  }
}
</script>
<style lang="less" scoped>
.box {
  display: flex;
  flex-direction: column;
  .tabs-app {
    flex: 1;
    display: flex;
    flex-direction: column;
    /deep/.ivu-tabs-content {
      flex: 1;
    }
  }
}
.title {
  font-size: 18px;
  font-weight: bold;
  padding: 14px;
}
</style>
